---
title: "Figure 1_Cameron_Morrell et al. 2024"
output: html_document
date: "2023-06-24"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
getwd()
setwd("/Users/lilymorrell/Desktop/Cameron_Morrell_2024/figures") #Replace the Working Directory site to match where you've stored your input files for easy access.
```

```{r}
library(tidyverse)
library(ggplot2)
library(readxl)
library(RColorBrewer)
library(ggpubr)
```

```{r}
data <- read_excel ("Figure1.xlsx", sheet = "data_PULESA")
datab<- read_excel("Figure1.xlsx", sheet = "data_PULESA_2")

data$USD <- as.numeric(data$USD)
datab$PERCENTAGE <- as.numeric(datab$PERCENTAGE)

```

```{r}
figure1 <- ggplot (data, aes(x=fct_reorder(Cat,Order),y=USD)) +
  scale_y_continuous(labels=scales::comma, limits = c(0,20)) +
  geom_col(aes(fill=Color), position = position_stack(reverse=TRUE), width=0.7)+
  theme_bw()+
  coord_flip()+ scale_fill_grey() +
  ggtitle("Average cost per visit (absolute, USD)") +
  theme(plot.title=element_text(hjust=0.5,size=12)) +
  theme(legend.title=element_blank())+
  theme (axis.title.y= element_blank()) +
  theme(legend.position = "bottom", legend.box = "horizontal", panel.grid.major.y=element_line(colour="white"), panel.grid.minor.y=element_line(colour="white"))

figure1

#ggsave('Figure1a.tiff', width=10.5, height=5.64, units="in", dpi=500)

```

```{r}
figure1a <- ggplot (data, aes(x=fct_reorder(Cat,Order),y=USD)) +
  scale_y_continuous(labels=scales::comma, limits = c(0,20)) +
  geom_col(aes(fill=Color), position = position_stack(reverse=TRUE), width=0.7)+
  theme_bw()+
  coord_flip()+ scale_fill_grey() +
  ggtitle("Average cost per visit (absolute, USD)") +
  theme(plot.title=element_text(hjust=0.5,size=10)) +
  theme(legend.title=element_blank())+
  theme (axis.title.y= element_blank()) +
  theme(legend.position = "none", panel.grid.major.y=element_line(colour="white"), panel.grid.minor.y=element_line(colour="white"),
        axis.title.x=element_text(size=9))

figure1a

```

```{r}
figure1b <- ggplot (datab, aes(x=fct_reorder(Cat,Order),y=PERCENTAGE)) +
  scale_y_continuous(labels=scales::comma) +
  geom_col(aes(fill=Color), position = position_stack(reverse=TRUE), width=0.7)+
  theme_bw()+
  coord_flip()+ scale_fill_grey() +
  ggtitle("Average cost per visit (relative contribution)") +
  xlab("PERCENTAGE") +
  theme(plot.title=element_text(hjust=0.5,size=10)) +
  theme(legend.title=element_blank())+
  theme (axis.title.y= element_blank()) +
  theme(legend.position = "none", panel.grid.major.y=element_line(colour="white"), panel.grid.minor.y=element_line(colour="white"), axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(), axis.title.x=element_text(size=9))


figure1b

```

```{r}
final <- ggarrange (figure1a,figure1b, widths = c(1.25,1))

final
ggsave('Figure1.tiff', width=10.5, height=5.64, units="in", dpi=500)


```

